package info.tsukaworld.actor.mob;

import info.tsukaworld.actor.AnimatedActor;
import info.tsukaworld.grid.*;
import info.tsukaworld.actor.mob.pathfinding.*;
import info.tsukaworld.actor.Player;
import java.util.List;
import java.util.ArrayList;
import info.tsukaworld.gui.*;

public class ControlledMob extends Mob
{
    private Location target;
    
    public void idleMove()
    {}
    
    public void processAggro()
    {
        if(getTargetLocation() == null )
            setAggro(Game.mouseListener.getClickedY() > 40 && Game.mouseListener.getClickedY() < 690);
        else
        {
            //will only aggro if the target location is not already reached and is empty
            setAggro( !(getLocation().equals(getTargetLocation())) && getGrid().get(getTargetLocation()) == null);
        }
    }
    
    public Location getTargetLocation()
    {
        if( Game.mouseListener.getClickedY() <= 40 || Game.mouseListener.getClickedY() > 690)
        {
            return null;
        }
        else
        {
            return new Location( (Game.mouseListener.getClickedY() - 40) / 50, 
                Game.mouseListener.getClickedX() / 50);
        }
    }
    
    public void followPath()
    {
        Maze m = new ModifiableMaze(getGrid());
        int area = getGrid().getNumRows() * getGrid().getNumCols();
        AStar a = new AStar(new SimpleHeuristicCalculator(area)); 
        Path p = a.findPath(m, getLocation(), getTargetLocation());
        List<Tile> list = p.getTiles();
        if( list.size() < 3)
        {
            setDirection(getLocation().getDirectionToward(getTargetLocation()));
            if(canMove())
            {       
                startMove();
            }
            setAggro(false);
            
        }
        else
        {
            Location loc = list.get(1).getLocation();
            setDirection(getLocation().getDirectionToward(loc));
            if(canMove())//&& currentHp > 0)  
                startMove();
        }
    }
}
    
    
        